package com.xjzd.std.concurrency;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(1000);
        for (int i = 0; i < 1000; i++) {
            int n = i;
            new Thread(() -> {
                long sum = 0;
                for (int j = 0; j < 100000000; j++) {
                    sum += j;
                }
                System.out.println(n + ": " + sum);
                countDownLatch.countDown();
            }).start();
        }

        countDownLatch.await();
    }
}
